package com.example.controller;

import com.example.Utils.UserHolder;
import com.example.model.Result;
import com.example.model.Review;
import com.example.model.User;
import com.example.service.IReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Hello
 * @since 2024-07-09
 */
@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    IReviewService iReviewService;
    @PostMapping("/uploadReview")
    Result<String> uploadReview(@RequestBody Review review) {
        User loginUser = UserHolder.getUser();
        Integer userId = loginUser.getUserId();
        if(!iReviewService.saveReview(String.valueOf(userId),review)){
            return Result.fail("失败");
        }
        return Result.success("成功");
    }
}
